package com.nattakute.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nattakute.dao.RoleDAO;
import com.nattakute.model.Role;

@Repository("roleDao")
public class RoleDAOImpl implements RoleDAO {

	@Autowired
	private SessionFactory sessionFactory;

	
	public Boolean removeRolebyId(Integer roleId) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public Boolean removeRole(Role role) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public Boolean addRole(Role role) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public Boolean updateRole(Role role) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public Role getRole(String userName) {
		// TODO Auto-generated method stub
		Role role =new Role();
		Criteria criteria=sessionFactory.getCurrentSession().createCriteria(Role.class);
		Criteria dCriteria=criteria.createCriteria("usersSet");
		dCriteria.add(Restrictions.eq("userName", userName));
		try {
			role=(Role) dCriteria.list().get(0);
			return role;
		} catch (Exception e) {
			role=null;
		}
		
		return role;
	}

	
	public Role getRoleById(Integer id) {
		Role role = new Role();
		try {
			role = (Role) sessionFactory.getCurrentSession().get(Role.class, id);
			return role;
		} catch (Exception e) {
			return null;
		}
	}

	
	@SuppressWarnings("unchecked")
	public List<Role> getRoleNotAdmin() {		
		List<Role> roles = new ArrayList<Role>();
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Role.class).add(Restrictions.not(Restrictions.eq("roleID", 1)));
		roles = criteria.list();		
		return roles;
	}
	
	
	
}
